package TwoAgain;

public class Accompli implements IUse{
    public static int number = 0;
    public Employee[] emp = new Employee[10];

    @Override
    public void add(Employee e) {
        emp[number] = e;
        number++;
        if (number==emp.length){
            addArray();
        }
    }

    private void addArray(){
        Employee[] newArray = new Employee[number+10];
        for (int i=0;i<number;i++){
            newArray[i] = emp[i];
        }
        emp = newArray;
    }


    @Override
    public String show() {
        String str = "姓名   性别   年龄   电话号码"+"\n";
        for (int i=0;i<number;i++){
            str += emp[i].getName()+"  "+emp[i].getSex()+"   "+emp[i].getAge()+"   "+emp[i].getPhNum()+"\n";
        }
        return str;
    }

    @Override
    public Employee search(String name) {
        for (int i=0;i<number;i++) {
            if (name.equals(emp[i].getName())){
                return emp[i];
            }
        }
        return null;
    }
}
